package dragon.simpleOAuth.oauth;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.provider.ClientDetailsService;

@Configuration
public class AuthorizationConfigurer extends AuthorizationServerConfigurerAdapter {

    @Autowired
    ClientDetailsService clientDetailsService;
    private String resourceId = "ll";
    private int accessTokenValiditySeconds = 1000;

//    @Override
//    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
//        clients.withClientDetails(clientDetailsService);
//        System.out.println("使用自定的clientDetailsService");
//    }


    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.withClientDetails(clientDetailsService);
        System.out.println("使用自定的clientDetailsService");

                clients.inMemory().withClient("cli0")
                .authorizedGrantTypes("authorization_code", "implicit")
                .authorities("ROLE_CLIENT")
                .scopes("read","write")
                .resourceIds(resourceId)
                .accessTokenValiditySeconds(accessTokenValiditySeconds)//授权码存活时间
                .and()
                .withClient("cli1")
                .authorizedGrantTypes("client_credentials", "password","authorization_code")
                .authorities("ROLE_TRUSTED_CLIENT")
                .scopes("server", "write")
                .resourceIds(resourceId)
                .accessTokenValiditySeconds(accessTokenValiditySeconds)
                .secret("123456");
    }
}
